define(['../../../carrys/cityList','../../../carrys/jsonList','../../../../../js/lib/other/sweet-alert'],function(cityData,jsonList) {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','37');//显示底部文字
    	
    	//默认值
    	$scope.isHide = false,$scope.isActive = false,$scope.isshow_block = false;
    	var caseTypeList = jsonList.caseTypeData;
    	
    	var provinceList = new Array();
    	var cityListTemp = new Array();
    	var districtTemp = new Array();
    	$scope.provinceName3 = "",$scope.cityName3 ="",$scope.districtName3 = "";
    	collateData();//整理列表数据
    	
    	if($routeParams.flag != "" && $routeParams.flag != null){
    		queryCaseReleaseOutline($routeParams.flag);
    	}
    	
    	
    	//点击撤销并删除
    	$scope.cancleFn = function(){
    		var sweetData = {
					title : "",
					text : "确认要撤销并删除？",
					type : "",
					showCancelButton : true,
					closeOnConfirm : false
				};
    		FIREFLY(sweetData,function(){
				$timeout(function(){
					delIssueCase();
				},0);
			},function(){return;});
    	}
    	
    	//点击修改内容
    	$scope.editContent = function(){
    		$scope.isHide = true,$scope.isActive = true,$scope.isshow_block = true;
    	}
    	
    	//点击完成修改
    	$scope.confimEdit = function(){
    		if(! $scope.caseTitle){
    			$scope.$emit("promptAlertMsg","案件标题不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if(! $scope.plaintiffName){
    			$scope.$emit("promptAlertMsg","原告人姓名不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if(! $scope.defendantName){
    			$scope.$emit("promptAlertMsg","被告人姓名不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if(! $scope.caseType){
    			$scope.$emit("promptAlertMsg","案件类型不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if(! $scope.caseDescribe){
    			$scope.$emit("promptAlertMsg","案情描述不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if(isNaN($scope.caseAmt)){
    			$scope.$emit("promptAlertMsg","涉案金额格式不正确");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else if(! $scope.telNumber){
    			$scope.$emit("promptAlertMsg","联系电话不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    			return;
    		}else{
    			issueCase();
    		}
    	}
    	
    	//点击关闭案件类型
    	$scope.closeType = function(){
    		$scope.issCaselide_up = false;
    	}
    	
    	//点击显示案件类型
    	$scope.selectCaseType = function(){
    		$scope.issCaselide_up = true;
    		if($scope.caseType !=""){
				for(var j=0;j<caseTypeList.length;j++){
					if($scope.caseType == caseTypeList[j].name){
						caseTypeList[j].sel = true;
					}else{
						caseTypeList[j].sel = false;
					}
				}
    			$scope.caseTypeList = caseTypeList;
    		}else{
    			for(var j=0;j<caseTypeList.length;j++){
					caseTypeList[j].sel = false;
				}
    			$scope.caseTypeList = caseTypeList;
    		}
    		
    	}
    	
    	//选择案件类型
    	$scope.selectType = function(flag){
    		caseTypeList.forEach(function(e){
    			e.sel = false;
    		});
    		caseTypeList[flag].sel = true;
    	}
    	
    	//确认选择
    	$scope.confirmBtn = function(){
    		$scope.issCaselide_up = false;
    		for(var j=0;j<caseTypeList.length;j++){
				if(caseTypeList[j].sel){
					$scope.caseType = caseTypeList[j].name;
					break;
				}
			}
    	}
    	
    	
    	//删除发布案源
    	function delIssueCase(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	var idList = new Array();
        	idList[0] = $routeParams.flag;
        	bizInfo.idList = idList;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("cancelCaseRelease",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$scope.$emit("loadingChange",false);
						$timeout(function(){
							 history.back();
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    				},transData.promptTime);
		    			}
		    		});
    	}
    	
    	
    	//编辑并发布案源
    	function issueCase(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.caseReleaseId = $routeParams.flag;
        	bizInfo.caseTopic = $scope.caseTitle;
        	bizInfo.caseDesc = $scope.caseDescribe;
        	bizInfo.contactMobile = $scope.telNumber;
        	bizInfo.caseAmount = String($scope.caseAmt);
        	bizInfo.creditorName = $scope.plaintiffName;
        	bizInfo.debtorName = $scope.defendantName;
        	bizInfo.caseMemo = $scope.caseExplain;
        	bizInfo.caseType = $scope.caseType;
        	if($scope.provinceName3 !="" && $scope.cityName3 != ""){
        		if(($scope.provinceName3).province == "北京" || ($scope.provinceName3).province  == "上海" || ($scope.provinceName3).province  == "天津" || ($scope.provinceName3).province == "重庆"){
            		bizInfo.caseProvince = ($scope.cityName3).city;
            		bizInfo.caseCity = ($scope.districtName3).district;
            	}else{
            		bizInfo.caseProvince = ($scope.provinceName3).province;
            		bizInfo.caseCity = ($scope.cityName3).city;
            	}
        	}else{
        		if($scope.seProvinceName == "北京" || $scope.seProvinceName  == "上海" || $scope.seProvinceName  == "天津" || $scope.seProvinceName == "重庆"){
            		bizInfo.caseProvince = $scope.seCityName;
            		bizInfo.caseCity = $scope.seCountyName;
            	}else{
            		bizInfo.caseProvince = $scope.seProvinceName;
            		bizInfo.caseCity = $scope.seCityName;
            	}
        	}
        	
        	
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("changeCaseRelease",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$scope.$emit("loadingChange",false);
						$timeout(function(){
							$scope.$emit("goNext","/sucCaseSub")
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    				},transData.promptTime);
		    			}
		    		});
    	}
    	
    	//代理接口查询的发布详情
    	function queryCaseReleaseOutline(caseReleaseId){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.caseReleaseId = caseReleaseId;
    		$scope.$emit("loadingChangeNav",true);
    		bizProxy.queryProxyBizData("queryCaseReleaseOutline",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			if(tempData.body != "" && tempData.body != null && tempData.body != "[]"){
							$timeout(function(){
								$scope.$emit("loadingChangeNav",false);
								var issueData = JSON.parse(tempData.body);
								$scope.issueDate = issueData.releaseDate;
								$scope.caseTitle = issueData.caseTopic;
								$scope.plaintiffName = issueData.creditorName;
								$scope.defendantName = issueData.debtorName;
								$scope.caseType = issueData.caseType;
								$scope.caseDescribe = issueData.caseDesc;
								$scope.caseAmt = issueData.caseAmount*1;
								if(issueData.caseProvince == "北京市" || issueData.caseProvince == "上海市" || issueData.caseProvince == "天津市" || issueData.caseProvince == "重庆市"){
									$scope.seProvinceName = (issueData.caseProvince).replace("市","");
									$scope.seCityName = issueData.caseProvince;
									$scope.seCountyName = issueData.caseCity; 
								}else{
									$scope.seProvinceName = issueData.caseProvince;
									$scope.seCityName = issueData.caseCity;
									$scope.seCountyName = "请选择"; 
								}
								$scope.telNumber = issueData.linkMode;
								$scope.caseExplain = issueData.caseMemo;
							},0);
						}else{
							$scope.$emit("loadingChangeNav",false);
							$scope.$emit("promptAlertMsg","未查找到相关数据");
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
								history.back();
							},transData.promptTime);
						}
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChangeNav",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									history.back();
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChangeNav', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    					history.back();
		    				},transData.promptTime);
		    			}
		    		});
    	}
    	
    	
    	//显示省份
    	$scope.provinceData = provinceList;
    	//显示城市
    	$scope.clickCity = function(data,flag){
    		var cityList = new Array();
    		var provinceName = data.province;
    		for(var i=0;i<cityListTemp.length;i++){
    			if(cityListTemp[i].province == provinceName){
    				var tempData = {'city': cityListTemp[i].city};
    				cityList.push(tempData);
    			}
    		}
    		$scope.cityData = cityList;
    		
    	}
    	//显示地区
    	$scope.clickArea = function(data,flag) {
    		var districtList = new Array();
    		var districtList1 = new Array();
    		var cityName = data.city;
    		for(var i=0;i<districtTemp.length;i++){
    			if(districtTemp[i].city == cityName){
    				districtList = districtTemp[i].district;
    				break;
    			}
    		}
    		for(var i=0;i< districtList.length;i++){
    			var tempData = {'district':districtList[i]};
    			districtList1.push(tempData);
    		}
    		$scope.districtData = districtList1;
    	}
    	
    	//整理省份数据
    	function collateData() {
    		cityListTemp = new Array();
    		districtTemp = new Array();
			for(var key in cityData.addressDetail){
				var tempData = {"province":key};
				provinceList.push(tempData);
				collateCity(key,cityData.addressDetail[key]);
			}
    	}
    	//整理城市数据
		function collateCity(data1,data2) {
			for(var key in data2){
				var tempList = {'province':data1,'city': key};
				cityListTemp.push(tempList);
				districtCity(key,data2[key]);
			}
		}
		//整理县区数据
		function districtCity(data1,data2){
			var tempList = {'city': data1,'district': data2};
			districtTemp.push(tempList);
		}
    	
        $scope.$apply();
    }];
});